home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / LgcyPlus / disk2 / ALARMCLK._ / ALARMCLK.
Encoding:
Text File  |  2001-03-02  |  6.8 KB  |  205 lines

  1. 10    ! *********************************************************************
  2. 20    !  Example: Alarm Clock
  3. 30    !
  4. 40    !  This program builds a digital alarm clock. You can set an alarm
  5. 50    !  time using a SCROLLBAR. A TOGGLEBUTTON allows you to disable
  6. 60    !  or enable alarm operation. A PUSHBUTTON allows you to turn off
  7. 70    !  the alarm.
  8. 80    !
  9. 90    ! *********************************************************************
  10. 100   !
  11. 110   CLEAR SCREEN
  12. 120   OPTION BASE 1
  13. 130   !
  14. 140   INTEGER Alarmval,Hour,Minute,N,Noisy
  15. 150   Noisy=0
  16. 160   !
  17. 170   DIM A$[8],T$[8]
  18. 180   !
  19. 190   INTEGER Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
  20. 200   !
  21. 210   Black=0
  22. 220   White=1
  23. 230   Red=2
  24. 240   Yellow=3
  25. 250   Green=4
  26. 260   Cyan=5
  27. 270   Blue=6
  28. 280   Magenta=7
  29. 290   !
  30. 300   INTEGER A(6),Nlines
  31. 310   REAL Dw,Dh,Vh,Pw,Ph,Px,Py
  32. 320   !
  33. 330   GESCAPE CRT,3;A(*)       ! Get display bounds
  34. 340   Dw=A(3)-A(1)+1           ! Compute display width in pixels
  35. 350   Dh=A(4)-A(2)+1           ! Compute display height in pixels
  36. 360   STATUS CRT,13;Nlines     ! Get number of text lines on display
  37. 370   Vh=Dh*(1-6/Nlines)       ! Height above DISP line
  38. 380   !
  39. 390   Pw=320                   ! PANEL width is half display width
  40. 400   Ph=240                   ! Same for PANEL height
  41. 410   Px=(Dw-Pw)/2             ! Center panel horizontally
  42. 420   Py=(Vh-Ph)/2             ! Center panel above DISP line
  43. 430   !
  44. 440   ! Build the main PANEL
  45. 450   !
  46. 460   ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
  47. 470   CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":1.2*Pw,"HEIGHT":Ph)
  48. 480   CONTROL @Main;SET ("TITLE":" Example: Alarm Clock")
  49. 490   CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
  50. 500   CONTROL @Main;SET ("BACKGROUND":Blue)
  51. 510   CONTROL @Main;SET ("SYSTEM MENU":"Quit")
  52. 520   ON EVENT @Main,"SYSTEM MENU" GOTO Finis
  53. 530   !
  54. 540   ! Dimensions and coordinates for child widgets
  55. 550   !
  56. 560   REAL Ih,Iw                      ! Inside height and width
  57. 570   REAL Gw,Gh,Lw,Bw,Lh,Sw,Sh,Bgap  ! Child widget dimensions
  58. 580   REAL Y1,Y2,Y3,Y4,X1,X2          ! Child widget coordinates
  59. 590   !
  60. 600   STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
  61. 610   !
  62. 620   Gh=Ih*.05       ! Arbitrary height of vertical gap
  63. 630   Gw=Iw*.02       ! Arbitrary width of horizontal gap
  64. 640   Wh=Ih*.3        ! Arbitrary height of LABEL & BUTTON widgets
  65. 650   Lw=Iw*.6        ! Arbitrary width of LABEL widgets
  66. 660   !
  67. 670   X1=Gw           ! Right side of LABELs & SCROLLBAR
  68. 680   X2=X1+Lw+Gw     ! Right side of BUTTONs
  69. 690   Bw=Iw-(X2+Gw)   ! BUTTON width
  70. 700   Sw=Iw-2*Gw      ! SCROLLBAR width
  71. 710   !
  72. 720   Y1=Gh           ! Position of first row of widgets
  73. 730   Y2=Y1+Wh+Gh     ! Position of second row of widgets
  74. 740   Y3=Y2+Wh        ! Position of bottom of second row of widgets
  75. 750   Bgap=Ih-Y3      ! Height of bottom gap on PANEL
  76. 760   !
  77. 770   ! Create LABEL for time value
  78. 780   !
  79. 790   ASSIGN @Clock TO WIDGET "LABEL";PARENT @Main
  80. 800   CONTROL @Clock;SET ("X":X1,"Y":Y1,"WIDTH":Lw,"HEIGHT":Wh)
  81. 810   CONTROL @Clock;SET ("FONT":"18 BY 30,BOLD")
  82. 820   CONTROL @Clock;SET ("BACKGROUND":Black,"PEN":Red,"BORDER":0)
  83. 830   !
  84. 840   ! Create TOGGLEBUTTON to enable/disable alarm
  85. 850   !
  86. 860   ASSIGN @Toggle TO WIDGET "TOGGLEBUTTON";PARENT @Main
  87. 870   CONTROL @Toggle;SET ("X":X2,"Y":Y1,"WIDTH":Bw,"HEIGHT":Wh)
  88. 880   CONTROL @Toggle;SET ("FONT":"18 BY 16,BOLD","LABEL":" ENABLE ALARM")
  89. 890   !
  90. 900   ! Create LABEL for alarm value
  91. 910   !
  92. 920   ASSIGN @Alarm TO WIDGET "LABEL";PARENT @Main
  93. 930   CONTROL @Alarm;SET ("X":X1,"Y":Y2,"WIDTH":Lw,"HEIGHT":Wh)
  94. 940   !
  95. 950   ! Create PUSHBUTTON to stop alarm
  96. 960   !
  97. 970   ASSIGN @Stop TO WIDGET "PUSHBUTTON";PARENT @Main
  98. 980   CONTROL @Stop;SET ("X":X2,"Y":Y2,"WIDTH":Bw,"HEIGHT":Wh)
  99. 990   CONTROL @Stop;SET ("FONT":"18 BY 16,BOLD","LABEL":" STOP ALARM")
  100. 1000  CONTROL @Stop;SET ("LABEL":"STOP ALARM")
  101. 1010  !
  102. 1020  ! Create SCROLLBAR, then center
  103. 1030  !
  104. 1040  ASSIGN @Scroll TO WIDGET "SCROLLBAR";PARENT @Main
  105. 1050  CONTROL @Scroll;SET ("ORIENTATION":"HORIZONTAL")
  106. 1060  STATUS @Scroll;RETURN ("HEIGHT":Sh)
  107. 1070  Y4=Y3+(Bgap-Sh)/2
  108. 1080  CONTROL @Scroll;SET ("X":X1,"Y":Y4,"WIDTH":Sw)
  109. 1090  !
  110. 1100  ! Set scale on SCROLLBAR to run through minutes of day.
  111. 1110  ! Allow slider to be incremented by hour and minute values.
  112. 1120  !
  113. 1130  CONTROL @Scroll;SET ("MINIMUM":0,"MAXIMUM":1439)
  114. 1140  CONTROL @Scroll;SET ("MINOR INCREMENT":1,"MAJOR INCREMENT":60)
  115. 1150  !
  116. 1160  ! Set initial time and alarm
  117. 1170  !
  118. 1180  GOSUB Update
  119. 1190  GOSUB Newalarm
  120. 1200  !
  121. 1210  ! Make application visible
  122. 1220  !
  123. 1230  CLEAR SCREEN
  124. 1240  CONTROL @Main;SET ("VISIBLE":1)
  125. 1250  !
  126. 1260  ! Enable widget event
  127. 1270  !
  128. 1280  ON EVENT @Scroll,"CHANGED" GOSUB Newalarm
  129. 1290  ON CYCLE 1 GOSUB Update
  130. 1300  !
  131. 1310  ! Loop until the user presses a key, then exit
  132. 1320  !
  133. 1330  LOOP
  134. 1340    WAIT FOR EVENT
  135. 1350  END LOOP
  136. 1360  !
  137. 1370  ! ***************** End of Main Program **************************
  138. 1380  !
  139. 1390  ! This routine updates the clock time. If the alarm is on,
  140. 1400  ! (Noisy=1), it will beep.
  141. 1410  !
  142. 1420  ! Once it updates the time, it checks the time for a match against the
  143. 1430  ! alarm. If there is a match, it sets Noisy to cause an alarm, causes
  144. 1440  ! a beep, enables an event on the PUSHBUTTON to turn off the alarm,
  145. 1450  ! and turns the PUSHBUTTON red.
  146. 1460  !
  147. 1470 Update:!
  148. 1480  IF Noisy=1 THEN BEEP 3000,.15
  149. 1490  T$=TIME$(TIMEDATE)
  150. 1500  CONTROL @Clock;SET ("VALUE":T$)
  151. 1510  !
  152. 1520  STATUS @Toggle;RETURN ("VALUE":N)         ! Is alarm enabled?
  153. 1530  IF N=1 THEN                               ! Yes --
  154. 1540    IF A$=T$ THEN                           ! Compare time
  155. 1550      Noisy=1
  156. 1560      BEEP 3000,.15
  157. 1570      ON EVENT @Stop,"ACTIVATED" GOSUB Killnoise
  158. 1580      CONTROL @Stop;SET ("BACKGROUND":Red)
  159. 1590    END IF
  160. 1600  END IF
  161. 1610  RETURN
  162. 1620  !
  163. 1630  ! This routine turns off the alarm
  164. 1640  !
  165. 1650 Killnoise:!
  166. 1660  OFF EVENT @Stop,"ACTIVATED"
  167. 1670  CONTROL @Stop;SET ("BACKGROUND":Blue)
  168. 1680  Noisy=0
  169. 1690  RETURN
  170. 1700  !
  171. 1710  ! This routine updates the alarm value. The value provided by
  172. 1720  ! the SCROLLBAR is converted into a time strng that matches
  173. 1730  ! that provided by TIME$(TIMEDATE).
  174. 1740  !
  175. 1750 Newalarm:!
  176. 1760  STATUS @Scroll;RETURN ("VALUE":Alarmval)
  177. 1770  !
  178. 1780  Hour=Alarmval DIV 60
  179. 1790  SELECT Hour
  180. 1800  CASE 0
  181. 1810    A$="12"
  182. 1820  CASE 1 TO 9
  183. 1830    A$="0"&VAL$(Hour)
  184. 1840  CASE ELSE
  185. 1850    A$=VAL$(Hour)
  186. 1860  END SELECT
  187. 1870  A$=A$&":"
  188. 1880  !
  189. 1890  Minute=Alarmval MOD 60
  190. 1900  SELECT Minute
  191. 1910  CASE 0 TO 9
  192. 1920    A$=A$&"0"&VAL$(Minute)
  193. 1930  CASE ELSE
  194. 1940    A$=A$&VAL$(Minute)
  195. 1950  END SELECT
  196. 1960  A$=A$&":00"
  197. 1970  !
  198. 1980  CONTROL @Alarm;SET ("VALUE":A$)
  199. 1990  RETURN
  200. 2000  !
  201. 2010 Finis:!
  202. 2020  ASSIGN @Main TO *   ! Delete PANEL widget
  203. 2030  CLEAR SCREEN
  204. 2040  END
  205.